package com.minatest.server;

import java.net.InetSocketAddress;

import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
import org.apache.mina.filter.logging.LoggingFilter;
import org.apache.mina.filter.logging.MdcInjectionFilter;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;

public class ServerMain {

    private static final int PORT = 1234;
    
    public static void main(String[] args) throws Exception {
        //创建服务端Socket
        NioSocketAcceptor acceptor = new NioSocketAcceptor();
        //获取过滤器链，以便添加过滤器
        DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
        //创建Mdc注入过滤器
//        MdcInjectionFilter mdcInjectionFilter = new MdcInjectionFilter();
//        chain.addLast("mdc", mdcInjectionFilter);
        //在过滤器链头部/尾部添加过滤器
        chain.addLast("logging", new LoggingFilter());
        chain.addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory()));
        
        
        //添加服务端处理器
        acceptor.setHandler(new SeverHandler()); 
        acceptor.bind(new InetSocketAddress(PORT));
    }
}
